<template>
  <el-menu
    active-text-color="#ffd04b"
    background-color="#545c64"
    class="el-menu-vertical-demo"
    default-active="2"
    text-color="#fff"
    :collapse="!$store.state.HomeModule.navBool"
    @open="handleOpen"
    @close="handleClose"
    router
  >
    <!-- 遍历 -->
    <template
      v-for="item in router.options.routes[2].children"
      :key="item.path"
    >
      <!-- 带下拉的导航 -->
      <el-sub-menu :index="item.path" v-if="item.children">
        <template #title>
          <el-icon> <component :is="item.meta.icon"></component> </el-icon>
          <span>{{ item.meta.title }}</span>
        </template>
        <el-menu-item-group v-for="items in item.children" :key="items.path">
          <el-menu-item :index="items.path">{{
            items.meta.title
          }}</el-menu-item>
        </el-menu-item-group>
      </el-sub-menu>
      <!-- 不带下拉的导航 -->
      <el-menu-item :index="item.path" v-else>
        <el-icon><component :is="item.meta.icon"></component></el-icon>
        <span>{{ item.meta.title }}</span>
      </el-menu-item>
    </template>
  </el-menu>
</template>

<script setup lang="ts">
import { useRouter } from "vue-router";
import { onMounted } from "vue";
import { TrendCharts, Menu, List } from "@element-plus/icons-vue";
const handleOpen = (key: string, keyPath: string[]) => {
  console.log(key, keyPath);
};
const handleClose = (key: string, keyPath: string[]) => {
  console.log(key, keyPath);
};

let router = useRouter();
// onMounted(() => {
//   console.log("@@", router.options.routes[2].children);
// });
</script>

<style lang="scss">
.el-menu {
  width: auto;
}
</style>
